/* poporcb4.p - PURCHASE ORDER RECEIPT W/ SERIAL NUMBER CONTROL              */
/* Copyright 1986 QAD Inc. All rights reserved.                               */
/* $Id:: poporcb4.p 54213 2015-04-09 02:10:35Z kbh                         $: */
/* REVISION: 7.4           CREATED:  11/04/93    BY: bcm *H210*              */
/* REVISION: 7.4           MODIFIED: 11/04/93    BY: cdt *H184*              */
/*           7.4                     10/29/94    BY: bcm *GN73*              */
/* REVISION: 7.4      LAST MODIFIED: 10/21/97    BY: *H1G5* Seema Varma      */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98    BY: *L007* A. Rahane        */
/* REVISION: 8.6E     LAST MODIFIED: 05/09/98    BY: *L00Y* Jeff Wootton     */
/* REVISION: 8.6E     LAST MODIFIED: 06/17/98    BY: *L020* Charles Yen      */
/* REVISION: 9.0      LAST MODIFIED: 03/15/99    BY: *M0BG* Jeff Wootton     */
/* REVISION: 9.0      LAST MODIFIED: 04/16/99    BY: *J2DG* Reetu Kapoor     */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99    BY: *N014* PATTI GAULTNEY   */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00    BY: *N0KQ* myb              */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* Revision: 1.8.1.5  BY: Dan Herman DATE: 04/17/02 ECO: *P043*              */
/* Revision: 1.8.1.7  BY: Paul Donnelly (SB) DATE: 06/28/03 ECO: *Q00J*      */
/* Revision: 1.8.1.14     BY: Huaping Luo        DATE: 03/26/10  ECO: *R21W* */
/* Revision: 1.8.1.15     BY: Huaping Luo      DATE: 08/05/10  ECO: *R24L* */
/* Revision: 1.8.1.16     BY: Huaping Luo      DATE: 08/17/10  ECO: *R251* */
/*-Revision end---------------------------------------------------------------*/

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* ADDED NO-UNDO  AND ASSIGN  WHEREVER MISSING                             */
/* REPLACED FIND STATEMENTS WITH FOR FIRST FOR ORACLE PERFORMANCE          */

{us/bbi/mfdeclre.i}
{us/px/pxmaint.i}
{us/px/pxphdef.i ictrxr}

define shared variable ref like glt_ref.
define shared variable eff_date like glt_effdate.
define shared variable po_recno as recid.
define shared variable rcv_type like poc_rcv_type.
define shared variable pod_recno as recid.
define shared variable crtint_amt like trgl_gl_amt.

define variable pod_entity like si_entity.

for first po_mstr
   where recid(po_mstr) = po_recno no-lock:
end. /* FOR FIRST PO_MSTR */

for first pod_det
   where recid(pod_det) = pod_recno no-lock:
end. /* FOR FIRST POD_DET */

find first icc_ctrl no-lock where
   icc_ctrl.icc_domain = global_domain 
no-error.

for first poc_ctrl
   where poc_ctrl.poc_domain = global_domain 
no-lock:
   rcv_type = poc_rcv_type.
end. /* FOR FIRST POC_CTRL */


/* POST THE CREDIT TERMS INTEREST COMPONENT OF THE ITEM PRICE */
/* TO A STATISCAL ACCCOUNT FOR THE PO RECEIPT.                */
if crtint_amt <> 0 then do:

   /* INITIALIZE pod_entity */
   for first si_mstr
      where si_mstr.si_domain = global_domain 
       and  si_site = pod_site no-lock:
   end. /* FOR FIRST SI_MSTR */
   if available si_mstr then
      pod_entity = si_entity.

     {us/px/pxrun.i &PROC  = 'createGltDetRecord'
          &PROGRAM='ictrxr.p'
          &handle = ph_ictrxr
          &PARAM = "(input crtint_amt,
                     input ""RCT-PO"", /* glt_det trans type */
                     input pod_nbr, /* order #*/
                     input poc_crtapp_acct,
                     input poc_crtapp_sub,
                     input poc_crtapp_cc,
                     input pod_project,
                     input poc_crtacc_acct,
                     input poc_crtacc_sub,
                     input poc_crtacc_cc,
                     input pod_project,
                     input pod_entity,
                     input eff_date, /* effective date */
                     input icc_gl_sum, /* summarize */
                     input icc_mirror, /* audit */
                     input if available trgl_det then recid(trgl_det) else ? , /* recid(trgl_det) */
                     input if available tr_hist then recid(tr_hist) else ?, /* recid(tr_hist) */
                     input """", /* inter company ref# */
                     input """", /* currency*/
                     input 0,   /* exchange rate */
                     input 0,   /* exchange rate 2 */
                     input """", /* exchange rate type */
                     input 0,  /* currency amount */
                     input-output ref)"
                     &NOAPPERROR=true
                     &CATCHERROR=true}

end.
if not po_sched then do:
   close-po:
   do transaction on error undo, leave:
      if po_stat <> "c" then do:
         for each pod_det
            where pod_det.pod_domain = global_domain 
             and  pod_nbr = po_nbr
         no-lock:
            if pod_status <> "c" and pod_status <> "x" then
               leave close-po.
         end.
         assign
            po_stat = "c"
            po_cls_date = today.
      end.
   end.
end.
